#include"processBar.h"

#define NUM 102
#define TOP 100
#define STYLE '='

#define GREEN "\033[0;32;32m"
#define NONE "\033[m"

const char *lable="|\\-/";
char bar[NUM];

void processbar(int rate)
{
	if(rate<0||rate>100) return;

	printf(GREEN"[%-100s]"NONE"[%-2d%%][%c]\r",bar,rate,lable[rate%4]);
	fflush(stdout);
	bar[rate++]=STYLE;
	if(rate<100) bar[rate]='>';
}

void initbar()
{
	memset(bar,'\0',sizeof(bar));
}

//实现第一个版本的简单进度条
/*void processbar()
{
	char bar[NUM];
	memset(bar,'\0',sizeof(bar));
	
	int cnt=0;
	while(cnt<=TOP)
	{
		printf(GREEN"[%-100s]"NONE"[%-2d%%][%c]\r",bar,cnt,lable[cnt%4]);
		fflush(stdout);
		bar[cnt++]=STYLE;
		if(cnt<100) bar[cnt]='>';
		//sleep(1);
		usleep(100000);	
	
	}
	printf("\n");
}
*/		
		
